#include "stdafx.h"
#include "ISCPacketCreator.h"

CByteArray CISCPacketCreator::m_packet = CByteArray();

CByteArray &CISCPacketCreator::getPacket()
{
	return m_packet;
}

void CISCPacketCreator::cleanup()
{
	m_packet.destroy();
}

void CISCPacketCreator::_start(int cmd)
{
	m_packet.clear();

	m_packet.addByte(0x6b);
	m_packet.addInt(0); // taille du packet
	m_packet.addInt(cmd);
}

void CISCPacketCreator::_finish()
{
	m_packet.setInt(1, m_packet.size() - 5);
}

const CByteArray &CISCPacketCreator::auth(const stringc& password, const stringc& ip, const stringc& name, int maxPlayers)
{
	_start(ECMD_AUTH);

	m_packet.addString(password);
	m_packet.addString(ip);
	m_packet.addString(name);
	m_packet.addInt(maxPlayers);

	_finish();

	return m_packet;
}